import type from '../constants/global'
import Taro from '@tarojs/taro';
import {
  getNavbarHight
} from '@/utils/utils.js'
const INITIAL_STATE = {
  userInfo: Taro.getStorageSync('userInfo') || null,
  isLogin: Taro.getStorageSync('userInfo') ? true : false,
  isShowGrant: false,
  showBackTop: false,
  systemInfo: Taro.getSystemInfoSync(),
  basket: Taro.getStorageSync('basket') || [],
  basketUpdate: Taro.getStorageSync('basketUpdate') || false,
  navbarHeight: getNavbarHight() || 0,
  qiniuToken: '',
}
export default function globalState(state = INITIAL_STATE, action) {
  switch (action.type) {
    case type.UPDATE_GLOBALSTATE:
      return {
        ...state,
        ...action.value
      }
      default:
        return state
  }
}
